package com.ly.algorithm.offerpointer;

/**
 * @Classname Offer43
 * @Description TODO
 * @Date 2021/1/31 15:45
 * @Author 冷心影翼
 */
public class Offer43 {

    public static void main(String[] args) {
        Solution43 solution43 = new Solution43();
        System.out.println(solution43.countDigitOne(1000000000));
    }

}


class Solution43 {
    public int countDigitOne(int n) {
        int count = 0;
        for (int i = 1; i <= n; i++) {

            String s = i+"";
            for (int j = 0; j < s.length(); j++) {
                if(s.charAt(j) == '1') {
                    count++;
                }
            }
        }
        return count;
    }
}